
/**
 * 
 * 设置页面title信息
 */
function initTitle(){
	$(".info-header div.info-tr").each(function(){
		$(this).find("li").each(function(index){
			var title=$(this).text().replace(/\s*/ig,"");
			
			if(title.length ==0)
			{
				$(this).find("img").each(function(){
					var src=$(this).attr("src");
					if(src.lastIndexOf("search.png")>0){
						$(this).parent().attr("title","查看详情");
					}else if(src.lastIndexOf("icon1_07.png")>0){
						$(this).parent().attr("title","发布");
					}else if(src.lastIndexOf("del.png")>0){
						$(this).parent().attr("title","删除本条数据");
					}
				});
			}else{
				$(this).attr("title",title);
			}
			
		});
	});
}


/**
 * Created by xiatao on 2015/9/10.
 */
/**
 * 分页
 * @param current
 * @param pageCount
 * @param totalSize
 */
function commonPages(map){
    $("#commonsPage").createPage({
        current:parseInt(map.current),
        pageCount:parseInt(map.pageCount),
        totalSize:parseInt(map.totalSize),
        url:map.url,
        fillDiv:map.fillDiv,
        backFn:function(current,pageCount,totalSize,url,fillDiv){
            var resultMap={"current":parseInt(current),"isPage":"isPage","url":url,"fillDiv":fillDiv};
          
            var mapData=window.sessionStorage.getItem("mapData");
            var data=JSON.parse(mapData);

            
            searchPage(resultMap,data);
        }
    })
}

function searchPage(map,data){		
    var isPage=map.isPage;
    var current=1;
    if("isPage"==isPage){
        current=parseInt(map.current)
    }else{
        current=1;
    }
    var pageCount=$("#pageSelect").val();
    data.pageCount=parseInt(pageCount);
    data.current=current;
    $.ajax({
        url:map.url,
        type:"post",
        dataType:"json",
        data:data,
        success:function(d){
            var p= d.main;
            if(p.length==0){
            	//如果没有数据，添加图片隐藏分页
            	$("#searchBody").empty();
            	$("#noDataImg").removeClass('none')
            	$("#commonsPage").addClass('none')
            }else{
            	$("#noDataImg").addClass('none')
            	$("#commonsPage").removeClass('none')
            	var html='';
                
                for(var i=0;i< p.length;i++){
                    html+=createProHtml(p[i],i);
                }

                $(map.fillDiv).html(html);
                initTitle();
                if("isPage"==isPage){
                    $("#totalSize").html(d.pageTotal);
                }else{
                    $("#commonsPage").unbind();
                    var resultMap={"current":1,"pageCount":pageCount,"totalSize":d.pageTotal,"url":map.url,"fillDiv":map.fillDiv};
                    commonPages(resultMap);
                }
            }
            
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
    	  	alert("ajax result data Type error:"+textStatus);
    	  }
    });
}

